#include "h_needmanage.h"
#include "ui_h_needmanage.h"
#include "global.h"

h_needManage::h_needManage(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::h_needManage)
{
    ui->setupUi(this);
    tableviews();
}
void h_needManage::tableviews(){
    QString str=QString("select * from water_a_repair where hid='%1'").arg(global::userid);
    model.setQuery(str);
    ui->tableView->setModel(&model);
    ui->tableView->setColumnHidden(1,true);
    ui->tableView->setColumnHidden(5,true);
    ui->tableView->setColumnHidden(7,true);
    model.setHeaderData(0,Qt::Horizontal,"单号");
    model.setHeaderData(2,Qt::Horizontal,"学号");
    model.setHeaderData(3,Qt::Horizontal,"需求内容");
    model.setHeaderData(4,Qt::Horizontal,"处理结果");
//    model.setHeaderData(5,Qt::Horizontal,"目标楼栋");
    model.setHeaderData(6,Qt::Horizontal,"宿舍号");
    model.setHeaderData(8,Qt::Horizontal,"提出需求的学生姓名");
//    model.setHeaderData(8,Qt::Horizontal,"是否同意");
//    model.setHeaderData(9,Qt::Horizontal,"日期");
//    model.setHeaderData(10,Qt::Horizontal,"学生姓名");
}
h_needManage::~h_needManage()
{
    delete ui;
}

void h_needManage::on_acceptBtn_clicked()
{
    int row = ui-> tableView ->currentIndex().row();
    QString id=model.data(model.index(row,0)).toString();

    QSqlQuery query;
    QString str=QString("update water_a_repair set wflag='y' where wrid='%1'").arg(id);
    qDebug()<<str;
    if(query.exec(str)){
        QMessageBox::information(NULL,"tips","处理成功");
        tableviews();
    }
    else {
        QMessageBox::warning(NULL,"Error","处理失败");
    }
}

